<template>
  <div v-show="isShow" class="gotop" @click="goTop">
    <slot></slot>
  </div>
</template>

<script>
import goTop from "tool/animate";
import debounce from "tool/debounce";
export default {
  name: "GoTop",
  data() {
    return {
      isShow: false
    };
  },
  methods: {
    goTop() {
      goTop(window, 0);
    },
    onScroll() {
      let fn = () => {
       

        if (window.pageYOffset >= 700) {
          this.isShow = true;
        } else {
          this.isShow = false;
        }
      };
      // 防抖
      window.addEventListener("scroll",debounce(fn,200));
    }
  },
  created() {
    this.onScroll();
  },
  mounted() {}
};
</script>

<style lang='less' scoped>
.gotop {
  position: fixed;
  bottom: 100px;
  right: 0;
  z-index: 2;
  width: 25px;
  height: 25px;
  img {
    width: 100%;
    height: 100%;
    background-color: pink;
    border-radius: 50%;
  }
}
</style>